package com.egao.orderB.biz.impl;

import com.egao.common.core.damon.constant.UserConstant;
import com.egao.common.core.damon.results.BaseDao;
import com.egao.common.core.damon.results.PageResult2;

import com.egao.common.core.damon.utils.Utils;
import com.egao.common.system.entity.User;
import com.egao.orderB.biz.PutStorageBiz;
import com.egao.orderB.entity.ExStorage;
import com.egao.orderB.entity.PutStorage;
import com.egao.common.core.web.JsonResult;
import com.egao.orderB.entity.PutStorageAndInfo;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.jdbc.support.GeneratedKeyHolder;
import org.springframework.jdbc.support.KeyHolder;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.Map;
import java.util.List;

/**
 *
 * 数据层实现类
 * @author : Doman
 * @date : 2021-12-23 15:43:48
 * @version ：1.0
 */
@Repository
public class PutStorageBizImpl extends BaseDao implements PutStorageBiz {

	@Override
	public JsonResult list13(PageResult2<T> page, PutStorageAndInfo putStorageAndInfo, User loginUser) throws Exception {
		Map<String, String> map  = new HashMap<String, String>();
		RowMapper<PutStorageAndInfo> rm = new BeanPropertyRowMapper<PutStorageAndInfo>(PutStorageAndInfo.class);
		StringBuffer sql = new StringBuffer("select p.id,p.organization_id,p.specify_job_number");
    sql.append(",p.po_code,p.reference_id,p.so_code,p.customer_code");
		sql.append(",p.transfer_order_no,p.start_date,p.warehousing_date,p.arrival_date");
		sql.append(",p.vessel,p.voyage,p.carrier,p.product_name");
		sql.append(",p.product_type,p.pack_num,p.track_edi,p.delivery_state");
		sql.append(",p.total_gross_weight,p.volume_m3,p.cost_weight,p.weight_conversion_factor");
		sql.append(",p.billing_ton,p.bubble_separation,p.num,p.weight");
		sql.append(",p.volume,p.warehouse_name,p.billing_method,p.ex_storaged");
		sql.append(",p.create_time,p.create_user,p.update_time,p.update_user");
		sql.append(",suser.nick_name createName ");

		sql.append(",cpi.id putInfoId,cpi.put_in_storage_id,cpi.inside_remark");
		sql.append(",cpi.entrustment_remark,cpi.name,cpi.stock_num,cpi.salesman_id");
		sql.append(",cpi.salesman,cpi.examine_id,cpi.examine,cpi.customer_service_id");
		sql.append(",cpi.customer_service,cpi.oversea_customer_service,cpi.operater_id,cpi.operater");
		sql.append(",cpi.file_name,cpi.financial_affairs,cpi.booking_space,cpi.cabinet_num");
		sql.append(",cpi.bill_of_lading,cpi.customer_id,cpi.customer,cpi.booking_agent");
		sql.append(",cpi.dispatch_agent,cpi.customs_clearance_agent,cpi.product_code,cpi.product_num");
		sql.append(",cpi.trade_terms,cpi.reconciliation_date,cpi.booking_space_etd,cpi.dispatch_date");
		sql.append(",cpi.payment_path,cpi.terms_of_service,cpi.reference_number_edi,cpi.ctn_mawb");
		sql.append(",cpi.originating_area,cpi.arrival_area,cpi.place_of_receipt,cpi.origin_sz");
		sql.append(",cpi.transit_place,cpi.destination,cpi.hbl,cpi.consignee_id");
		sql.append(",cpi.consignee,cpi.notifier_id,cpi.notifier,cpi.pick_up_agent");
		sql.append(",cpi.shipping_mark,cpi.product_dec,cpi.shipping_address,cpi.remark");
    sql.append(" from chf_put_storage p ");
    sql.append(" inner join sys_user suser on suser.user_id=p.create_user ");
    sql.append(" left join chf_put_info cpi on cpi.put_in_storage_id=p.id and cpi.deleted=0 ");
    sql.append(" where p.deleted=0 ");
    if(Utils.isNotEmpty(putStorageAndInfo)){
			if(Utils.isNotEmpty(putStorageAndInfo.getExStoraged())){
				sql.append(" and p.ex_storaged=:ex_storaged ");
				map.put("ex_storaged", putStorageAndInfo.getExStoraged()+"");
			}
			if (Utils.isNotEmpty(putStorageAndInfo.getDate1())) {
				sql.append(" and p.create_time>= :date1 ");
				map.put("date1", putStorageAndInfo.getDate1());
			}
			if (Utils.isNotEmpty(putStorageAndInfo.getDate2())) {
				sql.append(" and p.create_time<=:date2 ");
				map.put("date2", putStorageAndInfo.getDate2());
			}
			if (Utils.isNotEmpty(putStorageAndInfo.getCustomer())) {
				sql.append(" and instr(cpi.customer, :customer)>0 ");
				map.put("customer", putStorageAndInfo.getCustomer());
			}
      if(Utils.isNotEmpty(putStorageAndInfo.getSort())&&Utils.isNotEmpty(putStorageAndInfo.getOrder())){
        sql.append(" order by p."+putStorageAndInfo.getSort()+" "+putStorageAndInfo.getOrder());
      } else {
        sql.append(" order by p.create_time desc");
      }
		}
		return jsonResult(getPageQueryList(page, sql.toString(), map, rm));
	}

	@Override
	public JsonResult list(PageResult2<T> page, PutStorage putStorage, User loginUser) throws Exception {
		Map<String, String> map  = new HashMap<String, String>();
		RowMapper<PutStorage> rm = new BeanPropertyRowMapper<PutStorage>(PutStorage.class);
		StringBuffer sql = new StringBuffer("select p.id,p.organization_id,p.specify_job_number");
    sql.append(",p.po_code,p.reference_id,p.so_code,p.customer_code");
		sql.append(",p.transfer_order_no,p.start_date,p.warehousing_date,p.arrival_date");
		sql.append(",p.vessel,p.voyage,p.carrier,p.product_name");
		sql.append(",p.product_type,p.pack_num,p.track_edi,p.delivery_state");
		sql.append(",p.total_gross_weight,p.volume_m3,p.cost_weight,p.weight_conversion_factor");
		sql.append(",p.billing_ton,p.bubble_separation,p.num,p.weight");
		sql.append(",p.volume,p.warehouse_name,p.billing_method,p.ex_storaged,p.order_num");
		sql.append(",p.create_time,p.create_user,p.update_time,p.update_user");
    sql.append(",sogzn.organization_name organizationName,suser.nick_name createName ");
    sql.append(" from chf_put_storage p ");
    sql.append(" inner join sys_user suser on suser.user_id=p.create_user ");
    sql.append(" inner join sys_organization sogzn on sogzn.organization_id=p.organization_id and sogzn.deleted=0 ");
    sql.append(" where p.deleted=0 ");
		if(loginUser.getUserId() != UserConstant.ADMIN_ID){
      sql.append(" and p.organization_id=:tableOrganizationId ");
      map.put("tableOrganizationId", loginUser.getOrganizationId() + "");
    }
    if(Utils.isNotEmpty(putStorage)){
//			if(Utils.isNotEmpty(putStorage.getName())){
//				sql.append(" and instr(p.name,:name)>0 ");
//				map.put("name", putStorage.getName());
//			}
      if(Utils.isNotEmpty(putStorage.getSort())&&Utils.isNotEmpty(putStorage.getOrder())){
        sql.append(" order by p."+putStorage.getSort()+" "+putStorage.getOrder());
      } else {
        sql.append(" order by p.create_time desc");
      }
		}
		return jsonResult(getPageQueryList(page, sql.toString(), map, rm));
	}

	@Override
	public List<PutStorage> list(PutStorage putStorage, User loginUser) {
		Map<String, String> map  = new HashMap<String, String>();
		RowMapper<PutStorage> rm = new BeanPropertyRowMapper<PutStorage>(PutStorage.class);
    StringBuffer sql = new StringBuffer("select p.id,p.organization_id,p.specify_job_number");
    sql.append(",p.po_code,p.reference_id,p.so_code,p.customer_code");
		sql.append(",p.transfer_order_no,p.start_date,p.warehousing_date,p.arrival_date");
		sql.append(",p.vessel,p.voyage,p.carrier,p.product_name");
		sql.append(",p.product_type,p.pack_num,p.track_edi,p.delivery_state");
		sql.append(",p.total_gross_weight,p.volume_m3,p.cost_weight,p.weight_conversion_factor");
		sql.append(",p.billing_ton,p.bubble_separation,p.num,p.weight");
		sql.append(",p.volume,p.warehouse_name,p.billing_method,p.ex_storaged,p.order_num");
		sql.append(",p.create_time,p.create_user,p.update_time,p.update_user");
    sql.append(",sogzn.organization_name organizationName,suser.nick_name createName ");
    sql.append(" from chf_put_storage p ");
    sql.append(" inner join sys_user suser on suser.user_id=p.create_user ");
    sql.append(" inner join sys_organization sogzn on sogzn.organization_id=p.organization_id and sogzn.deleted=0 ");
    sql.append(" where p.deleted=0 ");
		if(loginUser.getUserId() != UserConstant.ADMIN_ID){
      sql.append(" and p.organization_id=:tableOrganizationId ");
      map.put("tableOrganizationId", loginUser.getOrganizationId() + "");
    }
    if(Utils.isNotEmpty(putStorage)){
      if(Utils.isNotEmpty(putStorage.getSort())&&Utils.isNotEmpty(putStorage.getOrder())){
        sql.append(" order by p."+putStorage.getSort()+" "+putStorage.getOrder());
      } else {
        sql.append(" order by p.create_time desc");
      }
    }
		getMapParameter(sql, map);
		return jdbcTemplate.query(sql.toString(),map, rm);
	}

	@Override
	public List<PutStorage> listVolume(PutStorage putStorage, User loginUser) {
		Map<String, String> map  = new HashMap<String, String>();
		RowMapper<PutStorage> rm = new BeanPropertyRowMapper<PutStorage>(PutStorage.class);
		StringBuffer sql = new StringBuffer("");
//		if (putStorage.getPoCode().equals("day")) {
//			sql.append(" select sum(pg.total_volume) from chf_put_storage ps ");
//			sql.append(" inner join chf_put_goods pg on pg.put_in_storage_id=ps.id ");
//			sql.append(" where ps.warehousing_date=CURDATE() ");
//		} else if (putStorage.getPoCode().equals("week")) {
//			sql.append(" select sum(pg.total_volume) from chf_put_storage ps ");
//			sql.append(" inner join chf_put_goods pg on pg.put_in_storage_id=ps.id ");
//			sql.append(" where YEARWEEK(DATE_FORMAT(ps.warehousing_date,'%Y-%m-%d')) = YEARWEEK(NOW()) ");
//		} else if (putStorage.getPoCode().equals("quarter")) {
//			sql.append(" select sum(pg.total_volume) from chf_put_storage ps ");
//			sql.append(" inner join chf_put_goods pg on pg.put_in_storage_id=ps.id ");
//			sql.append(" where QUARTER(ps.warehousing_date)=QUARTER(NOW()) and DATE_FORMAT(ps.warehousing_date,'%Y') = DATE_FORMAT(NOW(),'%Y') ");
//		}
		sql.append(" select 'day' productName, if(sum(num) is null,0,sum(num)) num from ( ");
		sql.append(" select 'day' productName,sum(pg.total_volume) num from chf_put_storage ps ");
		sql.append(" inner join chf_put_goods pg on pg.put_in_storage_id=ps.id and pg.deleted=0 ");
		sql.append(" where ps.deleted=0 and ps.warehousing_date=CURDATE() ");
		sql.append("  group by productName ");
		sql.append("  ) a ");

		sql.append(" union all ");
		sql.append(" select 'week' productName, if(sum(num) is null,0,sum(num)) num from ( ");
		sql.append(" select 'week' productName,sum(pg.total_volume) num from chf_put_storage ps ");
		sql.append(" inner join chf_put_goods pg on pg.put_in_storage_id=ps.id and pg.deleted=0 ");
		sql.append(" where ps.deleted=0 and YEARWEEK(DATE_FORMAT(ps.warehousing_date,'%Y-%m-%d')) = YEARWEEK(NOW()) ");
		sql.append("  group by productName ");
		sql.append("  ) a ");

		sql.append(" union all ");
		sql.append(" select 'quarter' productName, if(sum(num) is null,0,sum(num)) num from ( ");
		sql.append(" select 'quarter' productName,sum(pg.total_volume) num from chf_put_storage ps ");
		sql.append(" inner join chf_put_goods pg on pg.put_in_storage_id=ps.id and pg.deleted=0 ");
		sql.append(" where ps.deleted=0 and QUARTER(ps.warehousing_date)=QUARTER(NOW()) and DATE_FORMAT(ps.warehousing_date,'%Y') = DATE_FORMAT(NOW(),'%Y') ");
		sql.append("  group by productName ");
		sql.append("  ) a ");

		getMapParameter(sql, map);
		return jdbcTemplate.query(sql.toString(),map, rm);
	}

	@Override
	public List<PutStorage> listMonth(PutStorage putStorage, User loginUser) {
		Map<String, String> map  = new HashMap<String, String>();
		RowMapper<PutStorage> rm = new BeanPropertyRowMapper<PutStorage>(PutStorage.class);
		StringBuffer sql = new StringBuffer("");
		sql.append(" select DATE_FORMAT(ps.warehousing_date,'%Y-%m') productName,count(1) num from chf_put_storage ps ");
		sql.append(" where ps.deleted=0 ");
//		sql.append(" where ps.deleted=0 and DATE_FORMAT(ps.warehousing_date,'%Y%m') = DATE_FORMAT(CURDATE(),'%Y%m') ");

		if (Utils.isNotEmpty(putStorage)) {
			if(Utils.isNotEmpty(putStorage.getDate1())) {
				sql.append("  and DATE_FORMAT(ps.warehousing_date,'%Y-%m')>=:date1 ");
				map.put("date1", putStorage.getDate1());
			}
			if (Utils.isNotEmpty(putStorage.getDate2())) {
				sql.append("  and DATE_FORMAT(ps.warehousing_date,'%Y-%m')<=:date2 ");
				map.put("date2", putStorage.getDate2());
			}
			if(Utils.isNotEmpty(putStorage.getKeywords())) {
				sql.append("  and DATE_FORMAT(ps.warehousing_date,'%Y-%m')=:keywords ");
				map.put("keywords", putStorage.getKeywords());
			}
		}
		sql.append("  group by productName ");

		getMapParameter(sql, map);
		return jdbcTemplate.query(sql.toString(),map, rm);
	}

	@Override
	public PutStorage getById(PutStorage putStorage) {
		RowMapper<PutStorage> rm = new BeanPropertyRowMapper<PutStorage>(PutStorage.class);
		Map<String, String> map  = new HashMap<String, String>();
		StringBuffer sql = new StringBuffer("select p.id,p.organization_id,p.specify_job_number");
    sql.append(",p.po_code,p.reference_id,p.so_code,p.customer_code");
		sql.append(",p.transfer_order_no,p.start_date,p.warehousing_date,p.arrival_date");
		sql.append(",p.vessel,p.voyage,p.carrier,p.product_name");
		sql.append(",p.product_type,p.pack_num,p.track_edi,p.delivery_state");
		sql.append(",p.total_gross_weight,p.volume_m3,p.cost_weight,p.weight_conversion_factor");
		sql.append(",p.billing_ton,p.bubble_separation,p.num,p.weight");
		sql.append(",p.volume,p.warehouse_name,p.billing_method,p.order_num");
		sql.append(",p.create_time,p.create_user,p.update_time,p.update_user");
    sql.append(",sogzn.organization_name organizationName,suser.nick_name createName ");
    sql.append(" from chf_put_storage p ");
    sql.append(" inner join sys_user suser on suser.user_id=p.create_user ");
    sql.append(" inner join sys_organization sogzn on sogzn.organization_id=p.organization_id and sogzn.deleted=0 ");
    sql.append(" where p.deleted=0 and p.id=:id ");
		map.put("id", putStorage.getId());
		getMapParameter(sql, map);
		return jdbcTemplate.queryForObject(sql.toString(), map, rm);
	}

	@Override
	public PutStorageAndInfo get13(PutStorageAndInfo putStorageAndInfo) {
		RowMapper<PutStorageAndInfo> rm = new BeanPropertyRowMapper<PutStorageAndInfo>(PutStorageAndInfo.class);
		Map<String, String> map  = new HashMap<String, String>();
		StringBuffer sql = new StringBuffer("select p.id,p.organization_id,p.specify_job_number");
		sql.append(",p.po_code,p.reference_id,p.so_code,p.customer_code");
		sql.append(",p.transfer_order_no,p.start_date,p.warehousing_date,p.arrival_date");
		sql.append(",p.vessel,p.voyage,p.carrier,p.product_name");
		sql.append(",p.product_type,p.pack_num,p.track_edi,p.delivery_state");
		sql.append(",p.total_gross_weight,p.volume_m3,p.cost_weight,p.weight_conversion_factor");
		sql.append(",p.billing_ton,p.bubble_separation,p.num,p.weight");
		sql.append(",p.volume,p.warehouse_name,p.billing_method,p.ex_storaged");

		sql.append(",cpi.id putInfoId,cpi.put_in_storage_id,cpi.inside_remark");
		sql.append(",cpi.entrustment_remark,cpi.name,cpi.stock_num,cpi.salesman_id");
		sql.append(",cpi.salesman,cpi.examine_id,cpi.examine,cpi.customer_service_id");
		sql.append(",cpi.customer_service,cpi.oversea_customer_service,cpi.operater_id,cpi.operater");
		sql.append(",cpi.file_name,cpi.financial_affairs,cpi.booking_space,cpi.cabinet_num");
		sql.append(",cpi.bill_of_lading,cpi.customer_id,cpi.customer,cpi.booking_agent");
		sql.append(",cpi.dispatch_agent,cpi.customs_clearance_agent,cpi.product_code,cpi.product_num");
		sql.append(",cpi.trade_terms,cpi.reconciliation_date,cpi.booking_space_etd,cpi.dispatch_date");
		sql.append(",cpi.payment_path,cpi.terms_of_service,cpi.reference_number_edi,cpi.ctn_mawb");
		sql.append(",cpi.originating_area,cpi.arrival_area,cpi.place_of_receipt,cpi.origin_sz");
		sql.append(",cpi.transit_place,cpi.destination,cpi.hbl,cpi.consignee_id");
		sql.append(",cpi.consignee,cpi.notifier_id,cpi.notifier,cpi.pick_up_agent");
		sql.append(",cpi.shipping_mark,cpi.product_dec,cpi.shipping_address,cpi.remark");
		sql.append(" from chf_put_storage p ");
		sql.append(" inner join sys_user suser on suser.user_id=p.create_user ");
		sql.append(" left join chf_put_info cpi on cpi.put_in_storage_id=p.id and cpi.deleted=0 ");
    sql.append(" where p.deleted=0 and p.id=:id ");
		map.put("id", putStorageAndInfo.getId());
		getMapParameter(sql, map);
		return jdbcTemplate.queryForObject(sql.toString(), map, rm);
	}

	@Override
	public Integer save(PutStorage putStorage, User loginUser) {
		GeneratedKeyHolder generatedKeyHolder = new GeneratedKeyHolder();
		KeyHolder keyHolder=new GeneratedKeyHolder();
		Map<String, String> map  = new HashMap<String, String>();
		StringBuffer sql =new StringBuffer("insert into chf_put_storage (");
    sql.append("organization_id,specify_job_number,po_code,reference_id");
		sql.append(",so_code,customer_code,transfer_order_no,start_date");
		sql.append(",warehousing_date,arrival_date,vessel,voyage");
		sql.append(",carrier,product_name,product_type,pack_num");
		sql.append(",track_edi,delivery_state,total_gross_weight,volume_m3");
		sql.append(",cost_weight,weight_conversion_factor,billing_ton,bubble_separation");
		sql.append(",num,weight,volume,warehouse_name");
		sql.append(",billing_method,order_num,create_user,create_time) values ( ");
    sql.append(":organization_id,:specify_job_number,:po_code,:reference_id");
		sql.append(",:so_code,:customer_code,:transfer_order_no,:start_date");
		sql.append(",:warehousing_date,:arrival_date,:vessel,:voyage");
		sql.append(",:carrier,:product_name,:product_type,:pack_num");
		sql.append(",:track_edi,:delivery_state,:total_gross_weight,:volume_m3");
		sql.append(",:cost_weight,:weight_conversion_factor,:billing_ton,:bubble_separation");
		sql.append(",:num,:weight,:volume,:warehouse_name");
		sql.append(",:billing_method,:order_num,:create_user,now())");
    map.put("organization_id", loginUser.getOrganizationId() + "");
    map.put("specify_job_number", putStorage.getSpecifyJobNumber());
    map.put("po_code", putStorage.getPoCode());
    map.put("reference_id", putStorage.getReferenceId());
    map.put("so_code", putStorage.getSoCode());
    map.put("customer_code", putStorage.getCustomerCode());
    map.put("transfer_order_no", putStorage.getTransferOrderNo());
    map.put("start_date", putStorage.getStartDate());
    map.put("warehousing_date", putStorage.getWarehousingDate());
    map.put("arrival_date", putStorage.getArrivalDate());
    map.put("vessel", putStorage.getVessel());
    map.put("voyage", putStorage.getVoyage());
    map.put("carrier", putStorage.getCarrier());
    map.put("product_name", putStorage.getProductName());
    map.put("product_type", putStorage.getProductType());
    map.put("pack_num", putStorage.getPackNum());
    map.put("track_edi", putStorage.getTrackEdi());
    map.put("delivery_state", putStorage.getDeliveryState());
    map.put("total_gross_weight", putStorage.getTotalGrossWeight());
    map.put("volume_m3", putStorage.getVolumeM3());
    map.put("cost_weight", putStorage.getCostWeight());
    map.put("weight_conversion_factor", putStorage.getWeightConversionFactor());
    map.put("billing_ton", putStorage.getBillingTon());
    map.put("bubble_separation", putStorage.getBubbleSeparation());
    map.put("num", putStorage.getNum()==null?null:putStorage.getNum()+"");
    map.put("weight", putStorage.getWeight()==null?null:putStorage.getWeight()+"");
    map.put("volume", putStorage.getVolume()==null?null:putStorage.getVolume()+"");
    map.put("warehouse_name", putStorage.getWarehouseName());
    map.put("billing_method", putStorage.getBillingMethod());
    map.put("order_num", putStorage.getOrderNum()==null?null:putStorage.getOrderNum()+"");
		map.put("create_user", loginUser.getUserId() + "");
		getMapParameter(sql, map);
		//		System.err.println("受到影响的行数=" + retVal + ",
		int retVal = this.jdbcTemplate.update(sql.toString(), new SqlParameterSource() {
			@Override
			public boolean hasValue(String paramName) {
				return map.containsKey(paramName);
			}
			@Override
			public Object getValue(String paramName) throws IllegalArgumentException {
				return map.get(paramName);
			}
		}, generatedKeyHolder);
		Integer id = generatedKeyHolder.getKey().intValue();
		return id;
	}

	@Override
	public boolean update(PutStorage putStorage, User loginUser) {
		Map<String, String> map  = new HashMap<String, String>();
		StringBuffer sql =new StringBuffer("update chf_put_storage set ");
    sql.append("specify_job_number=:specify_job_number,po_code=:po_code,reference_id=:reference_id ");
		sql.append(",so_code=:so_code,customer_code=:customer_code,transfer_order_no=:transfer_order_no ");
		sql.append(",start_date=:start_date,warehousing_date=:warehousing_date,arrival_date=:arrival_date ");
		sql.append(",vessel=:vessel,voyage=:voyage,carrier=:carrier ");
		sql.append(",product_name=:product_name,product_type=:product_type,pack_num=:pack_num ");
		sql.append(",track_edi=:track_edi,delivery_state=:delivery_state,total_gross_weight=:total_gross_weight ");
		sql.append(",volume_m3=:volume_m3,cost_weight=:cost_weight,weight_conversion_factor=:weight_conversion_factor ");
		sql.append(",billing_ton=:billing_ton,bubble_separation=:bubble_separation,num=:num ");
		sql.append(",weight=:weight,volume=:volume,warehouse_name=:warehouse_name ");
		sql.append(",billing_method=:billing_method,order_num=:order_num,update_time=now() ");
		sql.append(",update_user=:update_user where id=:id ");
    map.put("specify_job_number", putStorage.getSpecifyJobNumber());
    map.put("po_code", putStorage.getPoCode());
    map.put("reference_id", putStorage.getReferenceId());
    map.put("so_code", putStorage.getSoCode());
    map.put("customer_code", putStorage.getCustomerCode());
    map.put("transfer_order_no", putStorage.getTransferOrderNo());
    map.put("start_date", putStorage.getStartDate());
    map.put("warehousing_date", putStorage.getWarehousingDate());
    map.put("arrival_date", putStorage.getArrivalDate());
    map.put("vessel", putStorage.getVessel());
    map.put("voyage", putStorage.getVoyage());
    map.put("carrier", putStorage.getCarrier());
    map.put("product_name", putStorage.getProductName());
    map.put("product_type", putStorage.getProductType());
    map.put("pack_num", putStorage.getPackNum());
    map.put("track_edi", putStorage.getTrackEdi());
    map.put("delivery_state", putStorage.getDeliveryState());
    map.put("total_gross_weight", putStorage.getTotalGrossWeight());
    map.put("volume_m3", putStorage.getVolumeM3());
    map.put("cost_weight", putStorage.getCostWeight());
    map.put("weight_conversion_factor", putStorage.getWeightConversionFactor());
    map.put("billing_ton", putStorage.getBillingTon());
    map.put("bubble_separation", putStorage.getBubbleSeparation());
    map.put("num", putStorage.getNum()==null?null:putStorage.getNum()+"");
    map.put("weight", putStorage.getWeight()==null?null:putStorage.getWeight()+"");
    map.put("volume", putStorage.getVolume()==null?null:putStorage.getVolume()+"");
    map.put("warehouse_name", putStorage.getWarehouseName());
    map.put("billing_method", putStorage.getBillingMethod());
    map.put("order_num", putStorage.getOrderNum()==null?null:putStorage.getOrderNum()+"");
		map.put("update_user", loginUser.getUserId() + "");
		map.put("id", putStorage.getId());
		getMapParameter(sql, map);
		int count = jdbcTemplate.update(sql.toString(), map);
		return count > 0;
	}

	@Override
	public boolean updateExStoraged(PutStorage putStorage, User loginUser) {
		Map<String, String> map  = new HashMap<String, String>();
		StringBuffer sql =new StringBuffer("update chf_put_storage set ");
    sql.append("ex_storaged=:ex_storaged ");
		sql.append(",update_time=now() ");
		sql.append(",update_user=:update_user where id=:id ");
    map.put("ex_storaged", putStorage.getExStoraged()+"");
		map.put("update_user", loginUser.getUserId() + "");
		map.put("id", putStorage.getId());
		getMapParameter(sql, map);
		int count = jdbcTemplate.update(sql.toString(), map);
		return count > 0;
	}

	@Override
	public boolean updateNum(PutStorage putStorage, User loginUser) {
		Map<String, String> map  = new HashMap<String, String>();
		StringBuffer sql =new StringBuffer("update chf_put_storage set ");
		sql.append(" num=num + :num ");
		sql.append(" ,total_gross_weight = total_gross_weight + :total_gross_weight ");
		sql.append(" ,volume_m3 = volume_m3 + :volume_m3 ");
//    sql.append(" ,total_volume=total_volume + :total_volume ");
		sql.append(",update_time=now(),update_user=:update_user where id=:id ");
		map.put("num", putStorage.getNum()+"");
		map.put("total_gross_weight", putStorage.getTotalGrossWeight());
		map.put("volume_m3", putStorage.getVolumeM3());
//    map.put("total_volume", stock.getTotalVolume());
		map.put("update_user", loginUser.getUserId()+"");
		map.put("id", putStorage.getId());
		getMapParameter(sql, map);
		int count = jdbcTemplate.update(sql.toString(), map);
		return count > 0;
	}

	@Override
	public boolean remove(PutStorage putStorage, User loginUser) {
		int count = 0;
		Map<String, String> map = null;
		if(putStorage.getId().length()>0){
			for(String ID : putStorage.getId().split(",")){
				map  = new HashMap<String, String>();
				if(ID==null || ID.equals("")){ break; }
				StringBuffer sql =new StringBuffer("update chf_put_storage set deleted=1" +
						",update_user=:update_user, update_time=now() "
						+ " where id =:id ");
				map.put("update_user", loginUser.getUserId() + "");
				map.put("id", ID);
				getMapParameter(sql, map);
				count = jdbcTemplate.update(sql.toString(),map);
			}
		}
		return count > 0;
	}
}
